using System.Windows;
using System.Windows.Controls;
using MiniTheme.Ui.Enums;

namespace MiniTheme.Ui.Controls
{
    //自定义控件，Generic.xaml中定义了默认样式
    public class IconButton : Button
    {
        static IconButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(IconButton),
                new FrameworkPropertyMetadata(typeof(IconButton)));
        }
        # region 依赖属性(都是默认写法)
        // 图标类型枚举，由转换器转换成对应的UniCode字符串
        public static readonly DependencyProperty IconProperty =
            DependencyProperty.Register(
                nameof(Icon),
                typeof(IconType),
                typeof(IconButton),
                new PropertyMetadata(IconType.None));
        public IconType Icon
        {
            get => (IconType)GetValue(IconProperty);
            set => SetValue(IconProperty, value);
        }
        // 图标大小，默认16
        public static readonly DependencyProperty IconSizeProperty =
            DependencyProperty.Register(
                nameof(IconSize),
                typeof(double),
                typeof(IconButton),
                new PropertyMetadata(16.0));
        public double IconSize
        {
            get => (double)GetValue(IconSizeProperty);
            set => SetValue(IconSizeProperty, value);
        }
        // 图标和文本之间的间距，进而控制了边框和内容之间的距离
        public static readonly DependencyProperty SpacingProperty =
            DependencyProperty.Register(
                nameof(Spacing),
                typeof(double),
                typeof(IconButton),
                new PropertyMetadata(8.0));
        public double Spacing
        {
            get => (double)GetValue(SpacingProperty);
            set => SetValue(SpacingProperty, value);
        }
        // 背景边框的圆角半径
        public static readonly DependencyProperty CornerRadiusProperty =
            DependencyProperty.Register(
                nameof(CornerRadius),
                typeof(CornerRadius),
                typeof(IconButton),
                new PropertyMetadata(new CornerRadius(6)));
        public CornerRadius CornerRadius
        {
            get => (CornerRadius)GetValue(CornerRadiusProperty);
            set => SetValue(CornerRadiusProperty, value);
        }

        // 鼠标悬停时的背景色
        public static readonly DependencyProperty HoverBackgroundProperty =
            DependencyProperty.Register(
                nameof(HoverBackground),
                typeof(System.Windows.Media.Brush),
                typeof(IconButton),
                new PropertyMetadata(null));
        public System.Windows.Media.Brush HoverBackground
        {
            get => (System.Windows.Media.Brush)GetValue(HoverBackgroundProperty);
            set => SetValue(HoverBackgroundProperty, value);
        }

        // 按下时的背景色
        public static readonly DependencyProperty PressedBackgroundProperty =
            DependencyProperty.Register(
                nameof(PressedBackground),
                typeof(System.Windows.Media.Brush),
                typeof(IconButton),
                new PropertyMetadata(null));
        public System.Windows.Media.Brush PressedBackground
        {
            get => (System.Windows.Media.Brush)GetValue(PressedBackgroundProperty);
            set => SetValue(PressedBackgroundProperty, value);
        }

        #endregion
    }
}
